<template>
	<!-- 服务项目 -->
	<view class="serviceItems">
		<view class="servicetips">
			以下是您目前选择提供的服务项目
		</view>
		<!-- 项目-->
		<view class="serviceItems-wrap">
			<view class="service-item" v-for="(item,index) in serviceData" :key="item.id">
				<view class="service-item-img">
					<image :src="item.master_image" style="width: 100%; height: 100%;" mode=""></image>
				</view>
				<view class="service-item-right">
					<view class="flex-row-flex-start">
						<view class="name">
							{{item.name}}
						</view>
						<view class="time">
							服务时间 : {{item.duration}}小时
						</view>
					</view>

					<view class="time flex-row-flex-start">
						<view class="">
							接单地址:
						</view>
						<input v-model="item.site" style="background: #f4f4f4;width: 254rpx; font-size: 28rpx;"
							type="text" placeholder="无固定场所可不填写" />
					</view>

					<view class="time flex-row-flex-start">
						<view class="">
							最低消费:
						</view>
						<input v-model="item.mininum_order_price"
							style="background: #f4f4f4;width: 220rpx;font-size: 28rpx;" type="text"
							placeholder="请输入最低消费" />
					</view>
					<view class="money flex-row-flex-start">
						最低:{{item.minimum_price}}
						<u-number-box v-model="item.price" :min="item.minimum_price" :max="item.maximum_price"
							decimalLength='2'>
							<view slot="minus" class="minus">
								<u-icon name="minus" color="#FFFFFF" size="12"></u-icon>
							</view>
							<view slot="input" style="width: 70px;font-size: 32rpx;background: #f4f4f4;" class="input">
								￥<input type="number" v-model="item.price"> </view>
							<view slot="plus" class="plus">
								<u-icon name="plus" color="#FFFFFF" size="12"></u-icon>
							</view>
						</u-number-box>
						最高:{{item.maximum_price}}
					</view>


				</view>
				<view class="icon">
					<radio @click="tigger(item.id)" :value="item.id+''" :checked="serviceData[`${index}`].is_check" />

				</view>
			</view>
		</view>

		<view class="btn">
			<view class="btn-b" @click="Pushclick()">
				<text>确认</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		setService,
		getService
	} from "./api.js"
	export default {
		data() {
			return {
				prices: [],
				service_ids: [],
				serviceData: [],
				site: [],
				mininum_order_price: [],
			}
		},
		onLoad() {
			this.getServiceItem()

		},
		methods: {
			getSetService() {
				setService().then(res => {
					console.log(res)
				})
			},
			changeReadio(e) {
				console.log(e.detail)

			},
			tigger(index) {
				this.service_ids = []
				this.prices = []
				for (var i = 0; i < this.serviceData.length; i++) {
					if (this.serviceData[i].id == index) {
						this.serviceData[i].is_check = !this.serviceData[i].is_check

					}
				}





			},
			// 获取服务项目
			getServiceItem() {
				getService().then(res => {

					for (let i = 0; i < res.data.length; i++) {
						res.data[i].maximum_price = parseInt(res.data[i].maximum_price)
						res.data[i].minimum_price = parseInt(res.data[i].minimum_price)
						// res.data[i].site = parseInt(res.data[i].site)
						// res.data[i].mininum_order_price = parseInt(res.data[i].mininum_order_price)
					}
					this.serviceData = res.data
				})
			},
			Pushclick() {
				this.service_ids = []
				this.prices = []
				this.site = []
				this.mininum_order_price = []
				for (var i = 0; i < this.serviceData.length; i++) {
					if (this.serviceData[i].is_check) {
						this.service_ids.push(this.serviceData[i].id)
						this.prices.push(this.serviceData[i].price)
						this.site.push(this.serviceData[i].site)
						this.mininum_order_price.push(this.serviceData[i].mininum_order_price)
					}

				}

				this.setServiceItem(this.service_ids, this.prices, this.site, this.mininum_order_price, )
			},

			// 设置服务项目
			setServiceItem(a, b, site, mininum_order_price) {
				console.log(a, b, site, mininum_order_price)
				setService({
					service_ids: a,
					prices: b,
					sites: site,
					mininum_order_prices: mininum_order_price
				}).then(res => {
					uni.showToast({
						icon: 'none',
						title: '设置成功'
					})
				})
			},
		}
	}
</script>

<style lang="less">
	.minus {
		width: 22px;
		height: 22px;
		background-color: #28c375;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}

	.input {
		padding: 0 10px 0 0;
		display: flex;
		/* padding:  10rpx 20rpx 10rpx 20rpx ; */
	}

	.plus {
		width: 22px;
		height: 22px;
		background-color: #28c375;
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}

	.serviceItems {
		width: 100%;
		height: 100%;

		.servicetips {
			width: 96%;
			height: 88rpx;
			background: #fff;
			font-size: 28rpx;
			font-weight: 400;
			color: #000000;
			line-height: 88rpx;
			text-indent: 24rpx;
			margin: 0 auto;
			margin-top: 24rpx;

		}

		.serviceItems-wrap {

			width: 96%;
			margin: 20rpx auto;
			padding-bottom: 150rpx;

			.service-item {
				position: relative;
				width: 100%;
				// height: 302rpx;
				display: flex;
				align-items: center;
				background: #fff;
				margin-top: 24rpx;
				border-radius: 16rpx;
				padding: 10rpx 0;

				.service-item-img {
					width: 176rpx;
					height: 154rpx;
					background: #A8A8A8;
					border-radius: 12rpx;
					margin-left: 24rpx;
				}

				.service-item-right {
					margin-left: 24rpx;
					// height: 154rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.name {
						font-size: 32rpx;
						color: #000000;
					}

					.time {
						margin-left: 6rpx;
						font-size: 28rpx;
						color: #666666;
					}

					.money {
						font-size: 26rpx;
						color: #FFB83C;
					}
				}
			}
		}

		.icon {
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			right: 50rpx;
		}
	}

	.btn {
		width: 95%;
		height: 100rpx;
		background-color: #fff;
		position: fixed;
		z-index: 999;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		padding: 0 20rpx;

		.btn-b {
			width: 30%;
			height: 100%;
			border-radius: 20rpx;
			display: flex;
			color: #fff;
			justify-content: center;
			align-items: center;
			background-color: #28c375;

		}
	}
</style>